/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package agent.util;

import agent.AgentType;
import jade.core.AID;
import jade.core.Agent;
import jade.domain.DFService;
import jade.domain.FIPANames;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;

/**
 *
 * @author margus
 */
public class AgentUtil {

    public final static String AGENT_PREFIX = "a2b-";

    public static String getAgentLocalName(Class<?> agentClass) {
        return AGENT_PREFIX + agentClass.getSimpleName();
    }

    public static AID createLocalAid(Class<?> agentClass) {
        return new AID(getAgentLocalName(agentClass), AID.ISLOCALNAME);
    }
    
    public static void registerByName(Agent agent, AgentType agentType){
    	DFAgentDescription dfd = new DFAgentDescription();
        dfd.setName( agent.getAID() );     
        
        ServiceDescription sd  = new ServiceDescription();
        sd.setType( agentType.name() );
        sd.setName( agent.getLocalName() );
        dfd.addServices(sd);
        try {  
            DFService.register( agent, dfd );
            System.out.println("Hello! Physician-agent " + agent.getName() + " is ready.");
        }
        catch (jade.domain.FIPAException fe) {
            fe.printStackTrace(); 
        }
    }
}
